﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LibMinecraft.Server;
using LibMinecraft.Model.Packets;
using LibMinecraft.Model;

namespace PartyCraftServer.Commands
{
    class DeOPCommand : Command
    {
        public override bool RequiresOp
        {
            get { return true; }
        }

        public override string DefaultCommand
        {
            get { return "deop"; }
        }

        public override string Documentation
        {
            get { return "Removes [player]'s operator status.\nUsage: /deop [player]"; }
        }

        public override void ExecuteCommand(RemoteClient client, params string[] parameters)
        {
            if (parameters.Length != 1)
            {
                client.SendChat(ChatColor.Red + "Invalid parameters.  Use /deop [player]");
                return;
            }
            foreach (RemoteClient c in PartyCraft.Server.ConnectedClients
                .Where(p => p.PlayerEntity.Name == parameters[0]))
            {
                c.Tags["op"] = false;
            }
            PartyCraft.SendToOps(ChatColor.Blue + client.PlayerEntity.Name + " has de-opped " + parameters[0]);
            PartyCraft.Settings["player." + client.PlayerEntity.Name + ".op"] = "false";
        }
    }
}
